package com.elvende.web.client.view.life;

import com.elvende.web.client.service.life.LearningService;
import com.elvende.web.client.service.life.LearningServiceAsync;
import com.elvende.web.client.view.View;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;
import com.elvende.web.client.dto.Learning;
import com.elvende.web.client.presenter.life.LearningDrillPresenter;

public class LearningDrillView extends View implements LearningDrillPresenter.Display{
	
	interface LearningDrillUiBinder extends UiBinder<Widget, LearningDrillView> {}
	private static LearningDrillUiBinder uiBinder = GWT.create(LearningDrillUiBinder.class);
	LearningServiceAsync rpcService = GWT.create(LearningService.class);				

	@UiField 
	TextArea drill;
	
	@UiField
	Button fail;	
	@UiField
	Button pass;
	@UiField
	Button bingo;
	@UiField
	Label label;
	
	Learning activeWord;
	
	public LearningDrillView() {
		initWidget(uiBinder.createAndBindUi(this));	
		initGui();
	}
	
	 private void initGui(){	
		 
		 fail.setHTML("Fail");
		 pass.setHTML("pass");
		 bingo.setHTML("Bingo");
		 
		 controlWidget(fail);
		 controlWidget(pass);
		 controlWidget(bingo);
		
		 if (LearningView.studyList != null && LearningView.studyList.length>0){
			 activeWord = LearningView.studyList[0];
			 showQuestion(activeWord);	 
		 }		 		 
	 }
	 
	 protected void showQuestion(Learning data){
		 drill.setText(data.getName());
	 }
	 
	 @UiHandler("fail")
	  void onFailClicked(ClickEvent event) {
	 }		 
	 
	 @UiHandler("pass")
	  void onPassClicked(ClickEvent event) {
	 }		
	 
	 @UiHandler("drill")
	  void onDrillClicked(ClickEvent event) {
		 if (activeWord != null)
			 drill.setText(activeWord.getAnswer());
	 }		
	 
	 
	 @UiHandler("bingo")
	  void onBingoClicked(ClickEvent event) {
	 }	 	 
}
